Clover coverage report - Enterprise Web Services - 1.0
Coverage timestamp: Mon May 30 2005 17:10:32 CEST
file stats: LOC: 116   Methods: 4
NCLOC: 87   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
FileUtils.java 91.7% 86.7% 100% 88.5%
coverage coverage
 1   
 /*
 2   
  * Copyright 2003,2004 The Apache Software Foundation.
 3   
  * 
 4   
  * Licensed under the Apache License, Version 2.0 (the "License");
 5   
  * you may not use this file except in compliance with the License.
 6   
  * You may obtain a copy of the License at
 7   
  * 
 8   
  *      http://www.apache.org/licenses/LICENSE-2.0
 9   
  * 
 10   
  * Unless required by applicable law or agreed to in writing, software
 11   
  * distributed under the License is distributed on an "AS IS" BASIS,
 12   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13   
  * See the License for the specific language governing permissions and
 14   
  * limitations under the License.
 15   
  */
 16   
 package org.apache.geronimo.ews.ws4j2ee.utils;
 17   
 
 18   
 import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
 19   
 import org.apache.commons.logging.Log;
 20   
 import org.apache.commons.logging.LogFactory;
 21   
 
 22   
 import java.io.File;
 23   
 import java.io.FileInputStream;
 24   
 import java.io.FileOutputStream;
 25   
 import java.io.IOException;
 26   
 import java.io.InputStream;
 27   
 import java.io.OutputStream;
 28   
 import java.util.ArrayList;
 29   
 import java.util.Enumeration;
 30   
 import java.util.jar.JarFile;
 31   
 import java.util.zip.ZipEntry;
 32   
 import java.util.zip.ZipFile;
 33   
 
 34   
 /**
 35   
  * @author Srinath Perera (hemapani@opensource.lk)
 36   
  */
 37   
 public class FileUtils {
 38   
     protected static Log log =
 39   
             LogFactory.getLog(FileUtils.class.getName());
 40   
             
 41  11
     public static void copyFile(File in, File out) throws GenerationFault {
 42  11
         try {
 43  11
             FileInputStream ins = new FileInputStream(in);
 44  11
             FileOutputStream outs = new FileOutputStream(out);
 45  11
             copyFile(ins, outs);
 46  11
             ins.close();
 47  11
             outs.close();
 48   
         } catch (Exception e) {
 49  0
             throw GenerationFault.createGenerationFault(e);
 50   
         }
 51   
     }
 52   
     
 53   
                 
 54  11
     public static void copyFile(InputStream in, OutputStream out) throws GenerationFault {
 55  11
         try {
 56  11
             byte[] buf = new byte[1024];
 57  11
             int val = in.read(buf);
 58  11
             while (val > 0) {
 59  33
                 out.write(buf, 0, val);
 60  33
                 val = in.read(buf);
 61   
             }
 62  11
             out.close();
 63  11
             in.close();
 64   
         } catch (Exception e) {
 65  0
             log.error(e);
 66  0
             throw GenerationFault.createGenerationFault(e);
 67   
         }
 68   
     }
 69   
 
 70   
     public static int configCount = 0;
 71   
     private JarFile ajar;
 72   
     private static byte[] data = new byte[10 * 1024];
 73   
     private String dir;
 74   
 
 75  3
     public static ArrayList uncompressWar(File outDir, File WarFile) throws IOException {
 76  3
         ArrayList urls = new ArrayList();
 77  3
         ZipFile zippedWar = new ZipFile(WarFile);
 78  3
         Enumeration enties = zippedWar.entries();
 79  3
         File classesDir = new File(outDir, "WEB-INF/classes");
 80  3
         classesDir.mkdirs();
 81  3
         urls.add(classesDir);
 82  3
         while (enties.hasMoreElements()) {
 83  40
             ZipEntry entry = (ZipEntry) enties.nextElement();
 84  40
             if (entry.isDirectory()) {
 85   
             } else {
 86  19
                 if (entry.getName().startsWith("WEB-INF/classes")) {
 87  8
                     File out = new File(outDir, entry.getName());
 88  8
                     out.getParentFile().mkdirs();
 89  8
                     uncompressFile(zippedWar.getInputStream(entry), out);
 90   
                 }
 91  19
                 if (entry.getName().startsWith("WEB-INF/lib")) {
 92  0
                     File outJar = new File(outDir, entry.getName());
 93  0
                     uncompressFile(zippedWar.getInputStream(entry), outJar);
 94  0
                     urls.add(outJar);
 95   
                 }
 96   
             }
 97   
         }
 98  3
         return urls;
 99   
     }
 100   
 
 101  10
     public static void uncompressFile(InputStream is, File outFile) throws IOException {
 102  10
         outFile.getParentFile().mkdirs();
 103  10
         OutputStream os = new FileOutputStream(outFile);
 104  10
         int val = 1;
 105  10
         while (true) {
 106  34
             val = is.read(data, 0, 1024);
 107  34
             if (val < 0 || val == 0)
 108  10
                 break;
 109  24
             os.write(data, 0, val);
 110   
         }
 111  10
         is.close();
 112  10
         os.close();
 113   
     }
 114   
 
 115   
 }
 116